<#-- This is a Freemarker Template for generating iBatis Sql Map Files for the application -->

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd">

<sqlMap namespace="${clazz.className}">

	<resultMap id="result" class="${appNamespace}.${component.name}.model.${clazz.className}">
	<#list clazz.attributeList as attribute>
		<result property="${attribute.attributeName}" column="${attribute.columnName}" columnIndex="${attribute.indexInAttributeList}"/>
	</#list>
	</resultMap>

	<select id="get${clazz.className}ById" resultMap="result">
		select
    	<#list clazz.attributeList as attribute>
			${clazz.className?uncap_first}.${attribute.columnName}<#if attribute_has_next>,</#if>
		</#list>
		from ${clazz.tableName} ${clazz.className?uncap_first}
		where ${clazz.className?uncap_first}.${clazz.attributeList[0].columnName} = #value#
	</select>

	<select id="get${clazz.className}ListByCriteria" resultMap="result">
		select
    	<#list clazz.attributeList as attribute>
			${clazz.className?uncap_first}.${attribute.columnName}<#if attribute_has_next>,</#if>
		</#list>
		from ${clazz.tableName} ${clazz.className?uncap_first}
	</select>

	<insert id="insert${clazz.className}">
		insert into ${clazz.tableName} 
			(<#list clazz.attributeList as attribute>${attribute.columnName}<#if attribute_has_next>, </#if></#list>)
		values
			(<#list clazz.attributeList as attribute>#${attribute.attributeName}#<#if attribute_has_next>, </#if></#list>)
	</insert>

	<update id="update${clazz.className}">
		update ${clazz.tableName}
		set
		<#list clazz.attributeList as attribute>
			${attribute.columnName} = #${attribute.attributeName}#<#if attribute_has_next>, </#if>
		</#list>
		where ${clazz.attributeList[0].columnName} = #${clazz.attributeList[0].attributeName}#
	</update>

	<delete id="delete${clazz.className}">
		delete from ${clazz.tableName}
		where ${clazz.attributeList[0].columnName} = #value#
	</delete>

</sqlMap>

